/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.chat;

import bllInterface.ChatMessage;
import java.util.*;
import javax.swing.AbstractListModel;

/**
 *
 * @author salm
 */
public class ChatMessageModel extends AbstractListModel
{
    private boolean isBoss = false;
    private List<ChatMessage> messages;
    private List<byte[]> bytes;
    
    public ChatMessageModel()
    {
        this.messages = new LinkedList();
        this.bytes = new LinkedList();
    }
    
    @Override
    public int getSize()
    {
        return this.messages.size();
    }

    @Override
    public Object getElementAt(int index)
    {
        return this.messages.get(index);
    }
    
    public void addMessage( ChatMessage msg )
    {
        this.messages.add(msg);
        this.fireIntervalAdded(this, this.messages.size() - 1, this.messages.size());
    }
    
    public byte[] getBytes()
    {
        if( this.bytes.size() > 0 )
        {
            byte[] arr = this.bytes.get(0);
            this.bytes.remove(0);
            return arr;
        }
        return null;
    }
    
    public void addBytes( byte[] b )
    {
        this.bytes.add(b);
    }
    
    public void acceptKey()
    {
        this.fireIntervalAdded(true, this.messages.size() - 1, this.messages.size());
    }
    
    public boolean getIsBoss()
    {
        return this.isBoss;
    }
    
    public void setIsBoss( boolean isBoss )
    {
        this.isBoss = isBoss;
    }
}